package com.ningxia.water.controller;

import com.ningxia.water.entity.TsLicenseInfo;
import com.ningxia.water.reuslt.Result;
import com.ningxia.water.reuslt.ResultResponse;
import com.ningxia.water.service.ITsLicenseInfoService;
import com.ningxia.water.utils.CommonUtils;
import com.ningxia.water.vo.out.LicenseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/license")
@Api(tags = "基本信息-许可证API")
public class LicenseController {

    @Autowired
    private ITsLicenseInfoService licenseInfoService;


    /**
     * 获取license信息，可根据输入的用户名称applicant_name、许可证编号license以及 时间段 start，end
     * @param applicantName
     * @param license
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/getlicenseinfo")
    @ApiOperation("获取所有许可证信息")
    public Result getLicenseInfo(@RequestParam(value = "applicantName", required = false) String applicantName,
                                 @RequestParam(value = "license", required = false) String license,
                                 @RequestParam(value = "start", required = false) String start,
                                 @RequestParam(value = "end", required = false) String end){
        List<LicenseVo> list = licenseInfoService.getLicenseInfo(applicantName, license, start, end);
        return ResultResponse.getSuccessResult(list);
    }

    /**
     * 新增许可证信息
     * @param licenseInfo
     * @return
     */
    @PostMapping("/insertlicenseinfo")
    @ApiOperation("新增许可证信息")
    public Result insertLiceseInfo(@RequestBody TsLicenseInfo licenseInfo){
        return CommonUtils.commonResult(licenseInfoService.save(licenseInfo));
    }


    /**
     * 修改许可证信息
     * @param licenseInfo
     * @return
     */
    @PutMapping("/updatelicenseinfo")
    @ApiOperation("修改许可证信息")
    public Result updateLicenseInfo(@RequestBody TsLicenseInfo licenseInfo){
        return CommonUtils.commonResult(licenseInfoService.updateById(licenseInfo));
    }

    /**
     * 删除许可证信息
     * @param licenseId
     * @return
     */
    @DeleteMapping("deletelicenseinfo")
    @ApiOperation("删除许可证信息")
    public Result deleteLicenseInfo(@RequestParam Integer licenseId){
        return CommonUtils.commonResult(licenseInfoService.removeById(licenseId));
    }

}
